from application.dependency.TokenDependency import verify_token
from application.util.ResponseUtil import ResponseUtil
from application.enumeration.ContentTypeEnum import ContentTypeEnum
from application.logic import LikeLogic
from fastapi.responses import JSONResponse
from fastapi import APIRouter, Depends, Body, Query
from typing import Annotated

router: APIRouter = APIRouter(prefix="/like", tags=["点赞/喜欢"])


@router.post("/add", summary="添加喜欢")
async def add_like(target_id: Annotated[int, Body(embed=True)],
                   content_type: Annotated[ContentTypeEnum, Body(embed=True)] = ContentTypeEnum.NOTE,
                   user_id: int = Depends(verify_token)) -> JSONResponse:
    await LikeLogic.add_like(user_id=user_id, target_id=target_id, content_type=content_type)
    return ResponseUtil().success()


@router.post("/delete/{like_id:int}", summary="根据ID删除喜欢", dependencies=[Depends(verify_token)])
async def delete_like(like_id: int) -> JSONResponse:
    await LikeLogic.delete_like_by_id(like_id=like_id)
    return ResponseUtil().success()


@router.get("/list/{user_id:int}", summary="根据用户ID获取喜欢列表")
async def get_list_by_user_id(user_id: int, content_type: ContentTypeEnum = ContentTypeEnum.NOTE,
                              page: int = Query(default=1, ge=1),
                              page_size: int = Query(default=10, ge=1)) -> JSONResponse:
    result: list = await LikeLogic.get_list_by_user_id(user_id=user_id, content_type=content_type, page=page,
                                                       page_size=page_size)
    return ResponseUtil(data=result).success()
